//
//  TopSearchTableViewCell.m
//  
//
//  Created by 微 醺 on 15/10/7.
//
//

#import "TopSearchTableViewCell.h"
#import "TopSearchModel.h"

@interface TopSearchTableViewCell () <UIWebViewDelegate>

@end

@implementation TopSearchTableViewCell

#pragma mark - 重写初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.newsCategoryLabel = [[UILabel alloc]init];
        self.newsTitleWebView = [[UIWebView alloc]init];
        self.newsDescWebVIew = [[UIWebView alloc]init];
        self.model = [[TopSearchModel alloc]init];
        self.pointLabel = [[UILabel alloc]init];
        self.lineView = [[UIImageView alloc]init];
        
        [self.contentView addSubview:self.newsCategoryLabel];
        [self.contentView addSubview:self.newsTitleWebView];
        [self.contentView addSubview:self.newsDescWebVIew];
        [self.contentView addSubview:self.pointLabel];
        [self.contentView addSubview:self.lineView];

    }
    return self;
}

#pragma mark - 重写model类set方法
- (void) setModel:(TopSearchModel *)model
{
    if (_model != model) {
        _model = model;
       
    }
    [self.newsTitleWebView loadHTMLString:self.model.newsTitle baseURL:nil];
    [self.newsTitleWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= ’200%’"];
    [self.newsDescWebVIew loadHTMLString:self.model.newsDesc baseURL:nil];
    self.newsCategoryLabel.text = self.model.newsCategory;
}

- (void)layoutSubviews

{
//    AppDelegate *dele = [[UIApplication sharedApplication]delegate];
//    if (dele.isNight == 1) {
//        
//        self.backgroundColor = [UIColor lightGrayColor];
//        self.newsTitleWebView.backgroundColor = [UIColor lightGrayColor];
//        self.newsDescWebVIew.backgroundColor = [UIColor lightGrayColor];
//        self.newsDescWebVIew.opaque = NO;
//        self.newsTitleWebView.opaque = NO;
//        self.newsCategoryLabel.textColor = [UIColor blackColor];
//        self.lineView.backgroundColor = [UIColor colorWithRed:36.0f/255 green:169.0f/255 blue:225.0f/255 alpha:1];
//    }
//    else{
        self.backgroundColor = [UIColor whiteColor];
        self.newsTitleWebView.backgroundColor = [UIColor lightGrayColor];
        self.newsDescWebVIew.backgroundColor = [UIColor whiteColor];
        self.newsDescWebVIew.opaque = YES;
        self.newsTitleWebView.opaque = YES;
        self.newsCategoryLabel.textColor = [UIColor grayColor];
        self.lineView.backgroundColor = [UIColor lightGrayColor];
//    }
    
    self.newsTitleWebView.frame = CGRectMake(0 , 5.0/150*self.frame.size.height,375.0/375*[UIScreen mainScreen].bounds.size.width, 30.0/150*self.frame.size.height);
    self.newsTitleWebView.scrollView.scrollEnabled =NO;
    self.newsTitleWebView.userInteractionEnabled = NO;
    self.newsTitleWebView.delegate = self;
    
    self.lineView.frame = CGRectMake(0, SAHeight * 149, self.frame.size.width, SAHeight * 1);
//    self.lineView.backgroundColor = [UIColor lightGrayColor];
    
    
    self.newsCategoryLabel.frame = CGRectMake(10.0/375*self.frame.size.width, 30.0/150*self.frame.size.height, 80.0/375*self.frame.size.width, 30.0/150*self.frame.size.height);
    self.newsCategoryLabel.font = [UIFont systemFontOfSize:14];
    // self.newsCategoryLabel.backgroundColor = [UIColor redColor];
    self.newsCategoryLabel.textAlignment = 1;
    

    self.newsDescWebVIew.frame = CGRectMake(0, 55.0/150*self.frame.size.height, 375.0/375*[UIScreen mainScreen].bounds.size.width, 90.0/150*self.frame.size.height);
    self.newsDescWebVIew.scrollView.scrollEnabled = NO;
    self.newsDescWebVIew.userInteractionEnabled = NO;
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
